<template>
	<div class="shop-page-goods">
		<u-navbar :title="title"></u-navbar>
		<!-- 返回首页 -->
		<!-- <uni-bankhome /> -->
		<!-- 商品 -->
		<div class="contant">
			<view v-if="!goodsList.length" class="empty">暂无商品信息</view>
			<view v-else class="item" v-for="(item,index) in goodsList" :key="index"
				@click="navigateToGoodsDetail(item)">
				<u-image width="100%" height="330rpx" mode="aspectFill" :src="item.thumbnail">
					<u-loading slot="loading"></u-loading>
				</u-image>
				<div class="name wes-2">{{ item.goodsName }}</div>
				<view class="buyCount">
					<div class="score">{{item.score||0}}分</div>
					<div class="sale-num">月售 {{ item.monthSales|| "0" }}+</div>
				</view>
				<div class="price">
					{{item.memberPrice| unitPrice}}
				</div>

			</view>
		</div>
	</div>

</template>

<script>
	import {
		getGoodsList
	} from "@/api/goods.js";
	export default {
		data() {
			return {
				title: "",
				routerVal: "",
				goodsList: [],
				params: {
					pageNumber: 1,
					pageSize: 10,
					keyword: "",
					storeCatId: "",
					storeId: "",
				},
			};
		},
		onLoad(options) {
			this.routerVal = options;
			this.params.storeId = options.storeId;
			this.params.storeCatId = options.id;
			this.title = options.title;
		},
		onShow() {
			this.goodsList = []
			this.params.pageNumber = 1;
			this.getGoodsData();
		},
		onReachBottom() {
			this.params.pageNumber++;
			this.getGoodsData();
		},
		methods: {
			/**
			 * 跳转到商品详情
			 */
			navigateToGoodsDetail(val) {
				uni.navigateTo({
					url: `/pages/product/goods?id=${val.content.id}&goodsId=${val.content.goodsId}`,
				});
			},

			async getGoodsData() {
				// #TODO
				let goodsList = await getGoodsList(this.params);
				if (goodsList.data.success) {
					this.goodsList.push(...goodsList.data.result.records);
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.shop-page-goods {
		padding: 0 24upx;
		.contant {
			margin-top: 20rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			>.empty {
				width: 100%;
				display: flex;
				justify-content: center;
				margin-top: 40rpx;
			}

			.item {
				background: #fff;
				width: 49%;
				font-size: 26rpx;
				display: flex;
				flex-direction: column;
				border: 1px solid #f8f8f8;
				margin-bottom: 20rpx;
				border-radius: 16upx;
				overflow: hidden;
				padding-bottom: 24upx;

				.name {
					text-align: left !important;
					color: #333;
					padding: 0 20rpx;
					margin-top: 20rpx;
					overflow: hidden;
				}

				.price {
					font-weight: 500;
					color: $main-color;
					font-size: 32rpx;
					padding: 0 20rpx;
					margin-top: 20rpx;
					white-space: nowrap;
				}

				.buyCount {
					margin-top: 24upx;
					display: flex;
					padding: 0 20rpx;
					font-size: 24upx;
					justify-content: space-between;
					align-items: center;
					color: #999;

					.score {
						color: #ff8921;
						font-size: 26upx;
					}

					.sale-num {
						color: #adaaaa;
						font-size: 20upx;
					}
				}
			}
		}
	}
</style>
